// import { JSEncrypt } from 'jsencrypt'
import { JSEncrypt } from 'encryptlong'

// 加密
export function encryptData(publicKey: string, data: any) {
  const encrypt = new JSEncrypt()
  encrypt.setPublicKey(publicKey)
  const jsonData = JSON.stringify(data)
  const base64Data = encodeURIComponent(jsonData)
  return encrypt.encryptLong(base64Data)
}

// 解密操作
export function decryptData(privateKey: string, data: any) {
  const decrypt = new JSEncrypt()
  decrypt.setPrivateKey(privateKey)
  return JSON.parse(decrypt.decryptLong(data))
}
